



//
//  NEntPriseSearchResultVC.m
//  nncloud
//
//  Created by macfai on 2018/12/27.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NEntPriseSearchResultVC.h"
#import "NZhaopinCell.h"
#import "NMyQiyeViewController.h"
#import "NIndustryDataInqueryDetailVC.h"
#import "NCaiwuDataInqDetailVC.h"

@interface NEntPriseSearchResultVC ()<UITableViewDataSource,UITableViewDelegate,STPickerSingleDelegate>


@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArray;

@property(nonatomic,strong)NSArray *titleArray;

@property(nonatomic,strong)NSArray *pickerArray;

@property (nonatomic,assign)NSInteger index;

@property (nonatomic,strong)NSDictionary *paraDict;


@end

@implementation NEntPriseSearchResultVC

#define cellIdentifier @"zhaopin"
#define SectionHeaderHeight  10.f

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 115.f;
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NZhaopinCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        _tableView.showsVerticalScrollIndicator = NO;
        //        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    
    
    [self.navigationItem setItemWithTitle:@"搜索结果" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    
    self.dataArray = [NSMutableArray array];
    [self.view addSubview:self.tableView];
    [self loadData];
}



- (void)loadData{
    //参数拼接
    //    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    //    //字典遍历，将一个字典的key value 赋给另一个字典
    //    [self.paraDict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
    //        [dict setObject:obj forKey:key];
    //    }];
    //
    //    [dict setObject:@100 forKey:@"size"];
    //    [dict setObject:@1 forKey:@"curPage"];
    //    //    NSDictionary *dic = self.paraDict?:@{@"size":@100,@"curPage":@1};
    
    [[NNRCNetRequest manager]getWithUrl:kQiyeListUrl params:self.dict?:@{} success:^(id result) {
        YYLog(@"%@",result);
        WeakStament(ws);
        if ([[result objectForKey:@"code"] integerValue] == 0) {
            NSArray *arr = result[@"page"][@"records"];
            if (arr.count>0) {
                YYLog(@"%@",arr);
                for (NSDictionary *dict in arr) {
                    NMyQiyeModel *model = [NMyQiyeModel mj_objectWithKeyValues:dict];
                    [ws.dataArray addObject:model];
                }
            }else{
                
                [AFToast showText:@"没有查到相关数据"];
                return ;
            }
            
            [ws.tableView reloadData];
        }else{
            [AFToast showText:result[@"msg"]];
        }
    } failure:^(id failure) {
        
    }];
}

#pragma mark - datasource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return  self.dataArray.count;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NMyQiyeModel*model = self.dataArray[indexPath.section];
    NZhaopinCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.salary.hidden = YES;
    cell.qModel = model;
    return cell;
}

#pragma mark - delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ///代码格式化快捷键  control+I（indent  缩进）
    ///从企业搜索入口进来的话push 的不是详情，而是对企业数据的查询因为只有政府端才会有这样的功能，所以通过登录类型来判断
    NMyQiyeModel *model = self.dataArray[indexPath.section];
    if ([[NUserModel shareInstance].userInfoType integerValue]==1) {
        //企业端  登录    跳转到企业详情
        NMyQiyeViewController *myQi = [NMyQiyeViewController new];
        myQi.eid = model.enterpriseId;
        myQi.userType = [NUserModel shareInstance].userInfoType;
        [self.navigationController pushViewController:myQi animated:YES];
    }else{
        ///政府端  登录   跳转到该企业的数据查询结果页面
        if ([NUserModel shareInstance].isIndustryDataInq) {
            NIndustryDataInqueryDetailVC *industry = [NIndustryDataInqueryDetailVC new];
            industry.eid = model.enterpriseId;
            [self.navigationController pushViewController:industry animated:YES];
        }else{
            
            NCaiwuDataInqDetailVC *caiwu = [NCaiwuDataInqDetailVC new];
            [self.navigationController pushViewController:caiwu animated:YES];
        }
        
    }
    
}

#pragma mark - section head
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
    view.backgroundColor = kBackgroundColor;
    return view;
}

#pragma mark - section foot
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

@end
